import { _decorator, Component, Node } from 'cc';
import { UserComponent } from './UserComponent';
import { KugoModel } from '../KugoModel';
import { SeatType } from '../proto/proto';
const { ccclass, property } = _decorator;

@ccclass('TopNode')
export class TopNode extends Component {


    private _userComponent:UserComponent []= []

    private _model:KugoModel = null
    onLoad() {
        this._model = KugoModel.getInstance()
        this._userComponent[0] = this.node.getChildByName("User1").getComponent(UserComponent)
        this._userComponent[1] = this.node.getChildByName("User2").getComponent(UserComponent)
    }

    refreshUser(){
        let whiteUser = this._model.UserMgr.getUserBySeatId(SeatType.WHITE)
        if (whiteUser) {
            this._userComponent[0].setData(whiteUser)
        }

        let blackUser = this._model.UserMgr.getUserBySeatId(SeatType.BLACK)
        if (blackUser) {
            this._userComponent[1].setData(blackUser)
        }
    }
    
}


